package com.object3D.wheel
{
	import com.engine.AwayEngine;
	import com.manager.CarMaterial;
	import com.object3D.BaseWheel;
	import com.utils.PowerLoader;
	
	import away3d.entities.Mesh;
	import away3d.loaders.misc.AssetLoaderContext;
	import away3d.materials.TextureMaterial;
	
	public class AudiR8Wheel extends BaseWheel
	{
		public function AudiR8Wheel()
		{
			super();
		}
		
		override protected function init():void
		{
			loadModel();
		}
		
		override protected function loadModel():void
		{
			PowerLoader.loadFile("models/audi/r8/R8WheelMtl.xml",loadMtl);
		}
		
		override protected function loadMesh(mesh:Mesh, name:Object):void
		{
			wheel = mesh.clone() as Mesh;
			wheel.scale(15);
			wheel3D.addChild(wheel);
			reviseMaterial(mesh)
		}
		
		protected function loadMtl(mtl:Object):void
		{
			var assetLoaderContext:AssetLoaderContext = new AssetLoaderContext(true);
			assetLoaderContext.mapUrlToData("R8Wheel.mtl",mtl);
			
			if(_path != null) PowerLoader.loadFile(_path,loadMesh,assetLoaderContext);
		}
		
		protected function reviseMaterial(mesh:Mesh):void
		{
			for(var i:int = mesh.numChildren - 1;i >= 0;i--)
			{
				var subMesh:Mesh = mesh.getChildAt(i) as Mesh;
				var subName:String = subMesh.name;
				var subMaterial:TextureMaterial = subMesh.material as TextureMaterial;
				subMaterial.lightPicker = AwayEngine.lightPicker;
				subMaterial.specular = 10;
				if(subName == 'Mesh_0239')
				{
					subMaterial.addMethod(CarMaterial.bodyReflection);
				}
				if(subName == 'Mesh_0258' || subName =='Mesh_0218')
				{
					subMaterial.addMethod(CarMaterial.getReflection(0.1));
				}
			}
		}	
		
		
	}
}